package com.test.demo.algorithm.utils;

import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;

public class PrintTime {

    public static int[] printTime(PrintTimeInterfaceFunction function, int[] array) throws Throwable {
        return printTime(function,array,ChronoUnit.NANOS);
    }

    public static int[] printTime(PrintTimeInterfaceFunction function, int[] array, ChronoUnit unit) throws Throwable {
        Instant start = Instant.now();
        int[] sort = function.sort(array);
        Instant end = Instant.now();
        Duration between = Duration.between(start, end);
        long time = between.get(unit);
        System.out.println("执行时间是："+time);
        return sort;
    }
}
